//
//  MineViewController.m
//  Utils
//
//  Created by enghou on 2018/4/12.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "MineViewController.h"
#import "LocalPersistent.h"
#import "NetWorkerManager.h"
#import "PersonalInfoViewController.h"
@interface MineViewController ()
@property(nonatomic,copy)NSString *name;
@property(nonatomic,copy)NSString *mobile;


@property (weak, nonatomic) IBOutlet UITableViewCell *lookCell;

@end

@implementation MineViewController

-(void)modifyReceiveMessage:(UISwitch *)sw{
    if (sw.on) {
        [[LocalPersistent sharedInstance]saveContent:@0 forKey:@"notRcvMsg"];
    }else{
        [[LocalPersistent sharedInstance]saveContent:@1 forKey:@"notRcvMsg"];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    [sw addTarget:self action:@selector(modifyReceiveMessage:) forControlEvents:UIControlEventValueChanged];
    BOOL notReceive = [[[LocalPersistent sharedInstance]contentForKey:@"notRcvMsg"]boolValue];
    if (notReceive) {
        sw.on = NO;
    }else{
        sw.on = YES;
    }
    self.thridCell.accessoryView = sw;
    
    UISwitch *sw1 = [[UISwitch alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    [sw1 addTarget:self action:@selector(modifyLook:) forControlEvents:UIControlEventValueChanged];
    BOOL look = [[[LocalPersistent sharedInstance]contentForKey:@"look"]boolValue];
    if (look) {
        sw1.on = YES;
    }else{
        sw1.on = NO;
    }
    self.lookCell.accessoryView = sw1;
}

-(void)modifyLook:(UISwitch *)sw{
    if (sw.on) {
        //关闭定时任务
        [[LocalPersistent sharedInstance]saveContent:@1 forKey:@"look"];
    }else{
        [[LocalPersistent sharedInstance]saveContent:@0 forKey:@"look"];
        //重启定时任务
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData];
}
- (IBAction)logoutAction:(id)sender {
    LoginViewController *login = [[LoginViewController alloc]init];
    [self.navigationController presentViewController:login animated:YES completion:nil];
}

-(void)loadData{
    [[NetWorkerManager sharedInstance]postWithPath:@"/mobile/comprehensiveGovernance/userMobileManage/getCurrentLoginUser.action" parameter:nil completeBlock:^(NSDictionary *source) {
        BaseModel *model = [[BaseModel alloc]initWithSourceDict:source];
        if (model.success) {
            NSDictionary *data = source[@"data"];
            self.nameLabel.text = data[@"userName"];
            self.descLabel.text = [NSString stringWithFormat:@"%@ %@",data[@"name"],data[@"mobile"]];
            self.name = data[@"name"];
            self.mobile = data[@"mobile"];
            NSString *headurl = [[LocalPersistent sharedInstance]contentForKey:@"headimage"];
            if (headurl) {
                [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headurl] placeholderImage:[UIImage imageNamed:@"icon_empty_head"]];
            }
            
        }else{
            [self alertSome:model.msg];
        }
    } failBlock:^(NSInteger code) {
        [self alertSome:kNetWorkFail];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"Personal"]) {
        PersonalInfoViewController *personal = [segue destinationViewController];
        personal.uid = [[LocalPersistent sharedInstance]contentForKey:@"uid"];
        personal.user_phone = self.mobile;
        personal.user_name = self.name;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
